$(function (){
    $("#topBtn").click(setTop);

    $("#wonderfulBtn").click(setWonderful);

    $("#deletedBtn").click(setDelete);
});



function like(btn, entityType, entityId, entityUserId, postId){
    $.post(
        CONTEXT_PATH + "/like",
        {"entityType": entityType, "entityId":entityId, "entityUserId":entityUserId, "postId":postId},
        function (data){
            data = $.parseJSON(data);
            if(data.code == 0){
                $(btn).children("i").text(data.likeCount);
                $(btn).children("b").text(data.likeStatus == 1?"已赞":"赞");
            }else {
                alert(data.msg);
            }
        }
    );
}

//置顶
function setTop(){
    $.post(
        CONTEXT_PATH + "/discuss/top",
        {"id": $("#postId").val()},
        function (data){
            data = $.parseJSON(data);
            if(data.code == 0){
                // 更改按钮属性，点击成功然后，按钮不可用
                $("#topBtn").attr("disabled", "disabled");

            }else {
                alert(data.msg);
            }
        }
    )
}

//加精
function setWonderful(){
    $.post(
        CONTEXT_PATH + "/discuss/wonderful",
        //传递参数
        {"id": $("#postId").val()},
        function (data){
            data = $.parseJSON(data);
            if(data.code == 0){
                // 更改按钮属性，点击成功然后，按钮不可用
                $("#wonderfulBtn").attr("disabled", "disabled");
            }else {
                alert(data.msg);
            }
        }
    )
}


//删除
function setDelete(){
    $.post(
        CONTEXT_PATH + "/discuss/delete",
        {"id": $("#postId").val()},
        function (data){
            data = $.parseJSON(data);
            if(data.code == 0){
                //跳转到首页
                location.href = CONTEXT_PATH + "/index";
            }else {
                alert(data.msg);
            }
        }
    )
}